%% @author Rain
%% @doc 时间相关基础接口


-module(util_time).

%% ====================================================================
%% API functions
%% ====================================================================
-export([get_now_time/0,
		 get_week/0,
		 seconds_to_datetime/1]).



%% ====================================================================
%% Internal functions
%% ====================================================================

%% @doc 获取当前时间
get_now_time() ->
	{MegaSecs, Secs, _MicroSecs} = os:timestamp(),
	MegaSecs * 1000000 + Secs.

%% @doc 获取当前周(1-7)
get_week() ->
	NowTime = get_now_time(),
	{Date, _Time} = seconds_to_datetime(NowTime),
	calendar:day_of_the_week(Date).

%% @doc 将unix时间戳转换成当地日期
seconds_to_datetime(Unixtime) ->
        Local = erlang:universaltime_to_localtime({{1970, 1, 1}, {0, 0, 0}}),
        LocalStamp = calendar:datetime_to_gregorian_seconds(Local),
        TimeStamp = Unixtime + LocalStamp,
        calendar:gregorian_seconds_to_datetime(TimeStamp).
